package nl.txproductions.twitterclient.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class MainWindow extends JFrame {

	private static final long serialVersionUID = -5733634340112296860L;
	private JList messageList;

	public MainWindow() {
		this.init();
	}

	private void init() {
		this.setSize(400, 800);
		
		// Get the size of the screen
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

		// Determine the new location of the window
		int w = this.getSize().width;
		int h = this.getSize().height;
		int x = (dim.width - w) / 2;
		int y = (dim.height - h) / 2;

		// Move the window
		this.setLocation(x, y);
		
		this.setResizable(false);
		this.getContentPane().setBackground(new Color(235, 244, 247));
		this.configureLayout();

		// add components
		this.add(this.createTitleLabel(), BorderLayout.PAGE_START);
	}

	public void setMessageList(JList messageList) {
		this.messageList = messageList;
		this.messageList.setVisible(true);
		this.add(new JScrollPane(this.messageList), BorderLayout.CENTER);
	}

	private void configureLayout() {
		this.setLayout(new BorderLayout());
	}

	private JLabel createTitleLabel() {
		JLabel label = new JLabel("Twitter Client");
		Font font = new Font("Calibri", Font.BOLD, 20);
		label.setFont(font);
		label.setHorizontalAlignment(JLabel.CENTER);

		return label;
	}
}